package com.yurun.orgparentmodule.service.Impl;

import com.yurun.commonapi.api.CommonResult;
import com.yurun.commonapi.pojo.StudentDocument;
import com.yurun.commonapi.vo.ChildAloneTrainingVo;
import com.yurun.orgparentmodule.mapper.AloneClassSummaryPhase202111Mapper2;
import com.yurun.orgparentmodule.mapper.ChildMapper;
import com.yurun.orgparentmodule.mapper.PerceptionMonthlySummary202111Mapper2;
import com.yurun.orgparentmodule.mapper.PerceptionTraining202111Mapper2;
import com.yurun.orgparentmodule.service.ChildService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.math.BigInteger;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class ChildServiceIml implements ChildService {
    @Autowired
    private ChildMapper childMapper;

    @Autowired
    private PerceptionMonthlySummary202111Mapper2 perceptionMonthlySummary202111Mapper2;

    @Autowired
    private AloneClassSummaryPhase202111Mapper2 aloneClassSummaryPhase202111Mapper2;

    @Autowired
    private PerceptionTraining202111Mapper2 perceptionTraining202111Mapper2;
//获取孩子信息
    @Override
    public CommonResult getChildInfoById(String studentId) {
        Map<String, Object> map = new HashMap<>();
//        System.out.println(studentId);
        String [] id = studentId.split(",");
        List<StudentDocument> studentDocuments = new ArrayList<>();
        for (int i = 0; i < id.length ; i++) {
            studentDocuments.add(childMapper.getChildInfoById(BigInteger.valueOf(Long.parseLong(id[i]))));
        }
        map.put("total",studentDocuments.size());
        map.put("data", studentDocuments);
//        return CommonResult.success(childMapper.getChildInfoById(studentId));
        return CommonResult.success(map);
    }
//获取孩子所有个训表
    @Override
    public CommonResult getChildAloneTrainWeek(String studentId, int pageNum, int pageSize) {
        String [] id = studentId.split(",");
        List<ChildAloneTrainingVo> result = new ArrayList<>();
        for (int i = 0; i < id.length; i++) {
            result.addAll(childMapper.getChildAloneTrainWeek(BigInteger.valueOf(Long.parseLong(id[i]))));
            result.addAll(childMapper.getChildAloneTrainQuarter(BigInteger.valueOf(Long.parseLong(id[i]))));
            result.addAll(childMapper.getChildAloneSensoryTrainWeek(BigInteger.valueOf(Long.parseLong(id[i]))));
            result.addAll(perceptionMonthlySummary202111Mapper2.getChildAloneSensoryTrainMonth(BigInteger.valueOf(Long.parseLong(id[i]))));
            result.addAll(aloneClassSummaryPhase202111Mapper2.getChildAloneClassTrainPhase(BigInteger.valueOf(Long.parseLong(id[i]))));
            result.addAll(perceptionTraining202111Mapper2.getChildAloneSensoryTrain(BigInteger.valueOf(Long.parseLong(id[i]))));
//            System.out.println(result);
        }
//        System.out.println(result);
        Map<String, Object> map = new HashMap<>();
//        List<ChildAloneTrainingVo> result1 = childMapper.getChildAloneTrainWeek(studentId);
//        List<ChildAloneTrainingVo> result2 = childMapper.getChildAloneTrainQuarter(studentId);
//        List<ChildAloneTrainingVo> result3 = childMapper.getChildAloneSensoryTrainWeek(studentId);
//        List<ChildAloneTrainingVo> result4 = perceptionMonthlySummary202111Mapper2.getChildAloneSensoryTrainMonth(studentId);
//        List<ChildAloneTrainingVo> result5 = aloneClassSummaryPhase202111Mapper2.getChildAloneClassTrainPhase(studentId);
//        List<ChildAloneTrainingVo> result6 = perceptionTraining202111Mapper2.getChildAloneSensoryTrain(studentId);
//        System.out.println(result4);
//        System.out.println(result);

//        result.addAll(result1);
//        result.addAll(result2);
//        result.addAll(result3);
//        result.addAll(result4);
//        result.addAll(result5);
//        result.addAll(result6);
        map.put("total", result.size());
        map.put("data", zljPageHelper(result, pageNum, pageSize));
//        System.out.println(map);
        return CommonResult.success(map);
//        return CommonResult.success(childMapper.getChildAloneTrainWeek(studentId));
    }

    public List<ChildAloneTrainingVo> zljPageHelper(List<ChildAloneTrainingVo> list, int pageNum, int pageSize) {
        List<ChildAloneTrainingVo> temp = new ArrayList<>();

        for (int i = pageSize * (pageNum - 1); i < list.size() && i < (pageSize * (pageNum - 1) + pageSize); i++) {
            temp.add(list.get(i));
        }
        return temp;
    }

//    @Override
//    public CommonResult getStudentids(BigInteger studentId, BigInteger organizationId, BigInteger branchId) {
//        String studentids = childMapper.getStudentids(organizationId, branchId);
//        String[] tokens = studentids.split(",");
//        for (i = 0; i < tokens.length; i++) {
//            if (studentId == tokens[i]) {
//
//            }
//
//        }
//    }


}
